from datetime import datetime

from selenium import  webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome(service = ChromeService(ChromeDriverManager().install()))

driver.get("https://www.baidu.com")

time.sleep(1)

driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("腾讯")

time.sleep(1)
driver.find_element(By.CSS_SELECTOR,"#kw").clear()

#获取标题
title = driver.title

driver.find_element(By.CSS_SELECTOR,"#su").click()
#获取url
url = driver.current_url


curwindow = driver.current_window_handle
allwindows = driver.window_handles
for window in allwindows:
    if window != curwindow:
        driver.switch_to.window(window)
time.sleep(1)

driver.maximize_window()
driver.minimize_window()
driver.fullscreen_window()
driver.set_window_size(1024, 721)



driver.save_sreenshot('../images/image.png')

filename = 'autotest' + datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') + '.png'
driver.save_screeshot('../image/' + filename)

#警告弹窗
alter = driver.switchTo.alter
alter.accept()
alter.dismiss()

#提示弹窗:
alter = driver.switchTo.alter
alter.send_keys('nihao')
alter.accept()
alter.dismiss()

driver.implicitly_wait(5)

driver.back()
driver.forward()
driver.refresh()


driver.close()
driver.quit()